//1. 公用样式
require('../../assets/css/index.less');
require('../../assets/css/basic.less');
require('../../assets/fonts/iconfont.css');
//2. 当前页面样式
require('./mybadge.less');
require('../../lib/swiper/swiper-bundle.css');


//3. 公用js
let dom = require('../../utils/dom.js');
let https = require('../../utils/https.js');
require('../../lib/swiper/swiper-bundle.js');


dom.ready(function () {


    // 调用
    dom.goback()

    // 定义一组图标数据
    let imgArr = [
        require('../../assets/imgs/mybadge01.jpg'),
        require('../../assets/imgs/mybadge02.jpg'),
        require('../../assets/imgs/mybadge03.jpg'),
        require('../../assets/imgs/mybadge04.jpg'),
        require('../../assets/imgs/mybadge05.jpg'),
        require('../../assets/imgs/mybadge06.jpg'),
        require('../../assets/imgs/mybadge07.jpg'),
        require('../../assets/imgs/mybadge08.jpg'),
        require('../../assets/imgs/mybadge09.jpg'),
    ]

    // 获取徽章数据
    function getBadge() {

        https.get('/api/exercise/badge', {}, function (res) {
            // console.log(res.data);
            // 判定
            if (res.errno == 0) {
                console.log(res.data);

                // 遍历添加内容
                res.data.map(function (v) {
                    // 拼接html结构添加到指定位置
                    myBadgeList.innerHTML += `
                            <li>
                                <img src="${imgArr[v.id-1]}" alt="">
                                <h2>${v.name}</h2>
                            </li>
                `
                })

                // 手动添加最后一个图
                myBadgeList.innerHTML += `
                <li>
                    <img src="${imgArr[imgArr.length-1]}" alt="">
                </li>
    `

            }
        })
    }

    //调用
    getBadge()



      // 获取个人信息
      function getUserInfo(){
        https.get('/api/user/info',{},function(res){
            console.log(res.data);
            if(res.errno==0){
                // local.set('userdata',res.data);
                // ES6
                let {badges}=res.data;
                badges1.innerHTML=badges;
            }
        })
    }  

    // 当网页加载时，直接进行调用
    getUserInfo();

})

